package com.ql.mangersystem.mapper;

import com.ql.mangersystem.common.Result;
import com.ql.mangersystem.entity.po.User;
import com.ql.mangersystem.entity.vo.AvatarVo;
import com.ql.mangersystem.entity.vo.PersonVo;
import com.ql.mangersystem.entity.vo.UserVo;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Entity com.ql.mangersystem.entity.po.User
 */
@Mapper
public interface UserMapper {
    @Select("select * from user where userAccount=#{userAccount} and password = #{password}")
    User login(@Param("userAccount")String userAccount,@Param("password") String password);

    @Insert("insert into `user` (userAccount,password,username,create_time,update_time) values (#{userAccount},#{password},#{username},#{createTime},#{updateTime})")
    Integer register(@Param("userAccount") String userAccount,@Param("password") String password,@Param("username") String username,@Param("createTime") LocalDateTime createTime, @Param("updateTime") LocalDateTime updateTime);
    @Select("select id from `user` where username = #{username} and deleted=1")
    Integer exists(String username);

    @Select("select id from `user` where userAccount = #{userAccount} and deleted =1 ")
    Integer isExistAccount(String userAccount);

    @Select("select * from `user` where id = #{id} and deleted = 1")
    User selectById(Integer id);

    @Select("select name,gender,phone,email,address,avatar from `user` where id = #{id}")
    PersonVo getById(Integer id);

    @Select("select avatar from `user` where id =#{id}")
    AvatarVo getAvatar(Integer id);

    @Update("update `user` set address=#{address},avatar=#{avatar},name=#{name},phone=#{phone},email=#{email},gender=#{gender},update_time=#{now} where id=#{userId} and deleted=1")
    int edit(@Param("address") String address, @Param("avatar") String avatar, @Param("name") String name, @Param("phone") String phone, @Param("email") String email, @Param("gender") Integer gender,@Param("userId") Integer userId,@Param("now")LocalDateTime now);

    @Update("update `user` set password =#{newPassword} where id =#{userId} and deleted =1")
    int changePassword(@Param("newPassword") String newPassword,@Param("userId") Integer userId);

    @Update("update `user` set password =#{password} where phone=#{phone} and name =#{name} and deleted =1")
    int forgetPassword(@Param("password") String password, @Param("phone") String phone, @Param("name") String name);

    @Select("select count(id) from `user` where deleted=1")
    Integer countId();

    @Select("select username,gender,phone,email,avatar,address from `user` where deleted=1 order by update_time desc limit #{skipNum}, #{pageSize}")
    List<UserVo> list(@Param("skipNum") Integer skipNum,@Param("pageSize") Integer pageSize);



    @Select("select username,gender,phone,email,avatar,address from `user` where deleted=1 order by update_time desc")
    List<UserVo> export();

    void saveBatch(@Param("userList") List<User> userList);

    @Select("select * from user where id =#{userid}")
    User getByUserId(Integer userid);

    @Select("select username from user where userAccount=#{userAccount}")
    String selectByAccount(String userAccount);

//    @Select("select count(id) from user")
//    Integer count(String userAccount);

//    @Update("update notice set open = #{change}")
//    Result openChange(Integer change);
}




